swev-id: sphinx-doc__sphinx-9258 - Support '|' union types in Python docfields (:type, :vartype) and add tests#78
Conversation
Test & Lint Summary
Full pytest run currently fails in this pinned Sphinx 4.1 / Python 3.10 environment (missing ImageMagick |
noa-lucent
left a comment
There was a problem hiding this comment.
Summary:\n- [major] Tighten the union delimiter detection: still fires inside literals like , so we end up splitting and cross-referencing the literal pieces. Please require whitespace on both sides without breaking spacing and add regression coverage for that case.\n- Please also update to mention the new union support so the docs stay accurate.
Test & Lint Summary
Full pytest run remains flaky in this pinned Sphinx 4.1 / Python 3.10 environment (missing ImageMagick |
noa-lucent
left a comment
There was a problem hiding this comment.
Summary:
- Regex now only treats
|as a union delimiter when it has whitespace on both sides, so literals likeLiteral['foo| bar']stay intact. - Regression tests cover the literal pipe case for both :type and :vartype fields.
- Documentation updated to mention the PEP 604-style union syntax and behavior for literal pipes.
Looks good to me—thanks!
Summary
|operator in Python docfields so each operand is linked independently.Linked Issue
Reproduction (before fix) on base branch (sphinx-doc__sphinx-9258)
nitpicky = TrueObserved failure output (before fix)
bytes | stris treated as a single reference target, which fails to resolve when nitpicky is enabled. Example warning:Fix
sphinx/domains/python.py: ExtendPyXrefMixin.make_xrefsdelimiter regex to split on|as a union delimiter (spaces around the operator).or, commas, brackets, or ellipsis.Tests
tests/test_domain_py.py:test_info_field_list_union_operator: verifiesbytes | str, legacystr or int or None, nested generics with unions, ellipsis unions, and literal pipe non-splitting.test_info_field_list_vartype_union: verifies vartype union linking.tests/roots/test-domain-py-union/for ad-hoc builds.Local results
convert) and known typing expectation diffs; this change is isolated to Python domain docfield linking and is covered by dedicated tests above.